package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.*;
import service.SegmentStrategyService;

import java.util.List;

@Controller
@RequestMapping("/segmentStrategy")
public class SegmentStrategyController {
    @Autowired
    private SegmentStrategyService segmentStrategyService;

    @RequestMapping("/getSegmentStrategyView")
    public String getSegmentStrategyView() {
        return "strategy/segmentStrategy";
    }

    @RequestMapping("/getSegmentView")
    public String getSegmentView() {
        return "strategy/segmentInfo";
    }

    @RequestMapping("/findAllSegmentStrategies")
    public @ResponseBody
    List<SegmentStrategy> findAllSegmentStrategies() throws Exception {
        return segmentStrategyService.findAllSegmentStrategies();
    }

    @RequestMapping("/findAllSegmentStrategyCustom")
    public @ResponseBody
    List<SegmentStrategyCustom> findAllSegmentStrategyCustom() throws Exception {
        return segmentStrategyService.findAllSegmentStrategyCustom();
    }

    @RequestMapping("/getAddSegmentStrategyView")
    public String getAddSegmentStrategyView() {
        return "strategy/addSegmentStrategy";
    }

    @RequestMapping("/addSegmentStrategy")
    public @ResponseBody
    Result addSegmentStrategy(SegmentStrategy segmentStrategy) {
        return segmentStrategyService.addSegmentStrategy(segmentStrategy);
    }

    @RequestMapping("/deleteSegmentStrategyById")
    public @ResponseBody
    Result deleteSegmentStrategyById(int id) {
        return segmentStrategyService.deleteSegmentStrategyById(id);
    }

    @RequestMapping("/getEditSegmentStrategyView")
    public String getEditSegmentStrategyView() {
        return "strategy/editSegmentStrategy";
    }

    @RequestMapping("/updateSegmentStrategy")
    public @ResponseBody
    Result updateSegmentStrategy(SegmentStrategy segmentStrategy) {
        return segmentStrategyService.updateSegmentStrategyById(segmentStrategy.getId(), segmentStrategy);
    }

    @RequestMapping("/getAddSegmentView")
    public String getAddSegmentView() {
        return "strategy/addSegment";
    }

    @RequestMapping("/addSegment")
    public @ResponseBody
    Result addSegment(Segment segment) {
        return segmentStrategyService.addSegment(segment);
    }

    @RequestMapping("/deleteSegment")
    public @ResponseBody
    Result deleteSegment(Segment segment) {
        return segmentStrategyService.deleteSegment(segment);
    }

    @RequestMapping("/findSegmentStrategyForComb")
    public @ResponseBody
    List<ComboboxItem> findSegmentStrategyForComb() throws Exception {
        return segmentStrategyService.findSegmentStrategyForComb();
    }
}
